package com.soft.controller;

import com.soft.pojo.Emp;
import com.soft.pojo.PageBean;
import com.soft.service.WorkService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author ruoxi
 * @create 2021-12-27 9:08
 */
@WebServlet("/showWorkerByEno")
public class ShowWorkerByEnoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String eno = req.getParameter("eno");

        if (eno == null || "".equals(eno)){
            resp.sendRedirect(req.getContextPath()+"/showAllEmpInfoByPage");
        }else {
            WorkService workService = new WorkService();
            PageBean<Emp> workerPg = new PageBean<>();
            ArrayList<Emp> emps = new ArrayList<>();
            emps.add((Emp) workService.findEmpByEno(eno).getData());

            workerPg.setCurrentPage(1);
            workerPg.setCurrentCount(1);
            workerPg.setTotalCount(1);
            workerPg.setTotalPage(1);
            workerPg.setList(emps);

            System.out.println(workerPg.getList().toString());

            req.setAttribute("workerPg", workerPg);
            req.getRequestDispatcher("worker.jsp").forward(req, resp);
        }
    }
}
